Optimal encoding of motion compensated video

ABSTRACT

The present invention involves a system and method for optimizing video encoding. For each candidate motion vector, encoding distortion is determined between a macroblock and a reconstructed macroblock by determining discrete cosine transform coefficients of the macroblock and quantizing the discrete cosine transform coefficients. An estimate unit estimates the length of the bit stream that would be required to encode the quantized discrete cosine transform coefficients along with the mode information bits including mode and motion vector information. The reconstructed macroblock is determined based on the quantized discrete cosine transform coefficients. A bit-rate term based on the length of the bit-rate stream is determined and included in the encoding distortion. The candidate motion vector which minimizes the encoding distortion of the macroblock is chosen to be the motion vector for the macroblock.

BACKGROUND OF THE INVENTION

1. Field of the Invention

This invention relates to the field of signal processing, and moreparticularly relates to a method and apparatus to optimize motion videoencoding using both distortion and bit-rate constraints.

2. Description of the Related Art

To represent a picture image digitally, the image area is described asan array of pixels. A digital number describes the color, luminance andchrominance of each pixel. Pixel color information consists of threedigital values: one digital value for red, one for green, and one forblue. Thus, a fairly large volume of data is required to describe onepixel. Accordingly, exceptionally large data files are required forcomplete picture images.

In full motion video, not only are large blocks of data required todescribe each picture image, but a new image or frame must be presentedto the viewer at approximately thirty new images per second to createthe illusion of motion. Moving these large streams of video data acrossdigital networks or phone lines is infeasible given currently availablebandwidth.

Data compression is a technique for reducing the number of bits requiredto represent a given image. Data compression techniques utilize either ashorthand notation to signal a repetitive string of bits or omit databits from the transmitted message. The latter form of compression iscalled “lossy” compression and capitalizes upon the ability of the humanmind to provide the omitted data. In motion video, much of the picturedata remains constant from frame to frame. Therefore, the video data maybe compressed by first describing a reference frame and describingsubsequent frames in terms of the change from the reference frame.

Several international standards for the compression of digital videosignals have emerged and more are currently under development. Thesestandards apply to algorithms for the transmission and storage ofcompressed digital video in a variety of applications, including:video-telephony and tele-conferencing; high quality digital televisiontransmission on coaxial and fiber-optic networks as well as broadcastterrestrially and over direct broadcast satellites; and in interactivemultimedia products on CD-ROM, Digital Audio Tape, and Winchester diskdrives.

Several of these standards involve algorithms based on a common core ofcompression techniques, e.g., the CCITT (Consultative Committee onInternational Telegraphy and Telephony) Recommendation H.120, the CCITTRecommendations H.261 and H.263, and the ISO/IEC MPEG-1, MPEG-2, andMPEG-4 standards. The MPEG algorithms were developed by the MovingPicture Experts Group (MPEG), as part of a joint technical committee ofthe International Standards Organization (ISO) and the InternationalElectrotechnical Commission (IEC). The MPEG standards describe acompressed representation of video and associated audio signals. Thestandard specifies the syntax of the compressed bit stream and themethod of decoding, but leaves considerable latitude for novelty andvariety in the algorithm employed in the encoder.

Motion compensation is commonly utilized by video encoders in signalprocessing techniques that compress successive frames of digital videodata for transmission via a communication medium of limited bandwidth,or for storing in a storage medium having limited storage capacity.Motion compensated video compression systems such as the ISO/ITUstandards of MPEG and H.261/3 use block-based motion estimation thatcompares a given block of one frame to a block of another frame. Blocksare matched by determining a comparison measurement between any givenpair of blocks. A comparison measurement corresponds to some form of adegree of “difference” between the two blocks. If the comparisonmeasurement is below a predetermined threshold, the blocks may beconsidered to be similar enough that a block match is indicated. If so,the block in the previous video frame may be utilized and only a motionvector is required to indicate the new position of the block in thecurrent video frame. Such motion vectors can be represented with fewerbits than the pixels that comprise the block, and fewer bits need to betransmitted (or stored) in order to recreate the block. A compressiontechnique known as transform coding is often used to generate a bitstream to be encoded as further described hereinbelow.

Motion compensation and encoding motion compensated video are of themost computationally intensive tasks that a video encoder performs. Theobjective of the encoder is to produce an encoded image represented in abit stream that provides the best visual quality for the rate of datatransfer, also referred to as bit-rate, allowed by the video codingstandards.

SUMMARY OF THE INVENTION

In one embodiment, a method for optimizing the video encoding processfor a macroblock in a block-based video encoder is provided, wherein aplurality of candidate motion vectors, mode vectors, and quantizeddiscrete cosine transform coefficients based on the macroblock and thecandidate motion vectors are provided. The method includes

(a) estimating the length of a bitstream that would be required toencode the quantized discrete cosine transform coefficients, the motionvectors, and the mode vectors;

(b) generating a bit-rate term based on the length of the bit stream;

(c) determining a measure of distortion based on quantized discretecosine transform coefficients;

(d) determining a rate-constrained distortion signal based on the blockdistortion and the bit-rate term;

(e) repeating (a) through (d) for each candidate motion vector and modevector; and

(f) selecting the motion vector corresponding the minimum motionestimation signal.

A Lagrange multiplier may be used to determine the bit-rate term in (b).Further, selected processes in the method may be executed in parallel todecrease time delay.

In another embodiment, an apparatus for optimal video encoding thatselects a motion vector and corresponding mode vector, and aquantization scale factor, for a current macro-block in a block basedvideo encoder is provided. A plurality of candidate motion vectors andcorresponding mode vectors, and quantized discrete cosine transformcoefficients based on the macroblock and the candidate motion vectorsand mode vectors are provided. The apparatus includes

a video encoder preprocessor connected to receive the quantized discretecosine transform coefficients, the candidate motion vectors, and thecandidate mode vectors, the video encoder preprocessor being operable toestimate the length of a bit stream that would be required to encodeeach candidate motion vector, corresponding mode vector, andcorresponding quantized discrete cosine transform coefficients, and totransmit the length of the bit stream;

a Lagrange multiplier unit connected to receive the length of the bitstream, the Lagrange multiplier unit being operable to generate abit-rate term based on the length of the bit stream, and to transmit thebit-rate term;

an inverse quantization unit connected to receive the discrete cosinetransform coefficients, the inverse quantization unit being operable todetermine inverse quantized discrete cosine transform coefficients andto transmit the inverse quantized discrete cosine transformcoefficients; and

a distortion calculator unit connected to receive the inverse quantizeddiscrete cosine transform coefficients, the distortion calculator unitbeing operable to generate a distortion signal.

The apparatus is further operable to determine a measure of distortionbased on the distortion signal and to determine a motion estimationsignal based on the measure of distortion and the bit-rate term for eachcandidate motion vector and corresponding mode vector, to select themotion vector having the minimum motion estimation signal, and to selecta quantization scale factor based on the measure of distortion and thebit-rate term. The selected motion vector and corresponding mode vectoris output to a buffer for transmission to a video encoder.

Advantageously, the present invention generates an estimate of thebit-rate term without requiring each candidate motion vector andcorresponding mode vector to be encoded.

BRIEF DESCRIPTION OF THE DRAWINGS

The video encoder preprocessor may be better understood, and itsnumerous objects, features, and advantages made apparent to thoseskilled in the art by referencing the accompanying drawings.

FIG. 1 is a block diagram of a processing system for a video encoder;

FIG. 2 is a block diagram of a video encoder in the prior art;

FIG. 3 is a block diagram of a video encoder preprocessor according tothe present invention; and

FIG. 4 is a block diagram of another video encoder preprocessoraccording to the present invention.

The use of the same reference symbols in different drawings indicatessimilar or identical items.

DETAILED DESCRIPTION

As the present invention may be applied in connection with an encodermeeting the industry standards, some pertinent aspects of standardcompression algorithms will be reviewed. It is to be noted that theinvention can be applied to video coding algorithms which share some ofthe following features.

It will be understood that the compression of any data object, such as apage of text, an image, a segment of speech, or a video sequence, can bebroken into a series of steps, including 1) decomposing the object intoa collection of tokens; 2) representing the tokens by binary stringswhich have minimal length in some sense; and 3) concatenating thestrings in a well-defined order. Steps 2 and 3 are lossless, i.e., theoriginal data is faithfully recoverable upon reversal. Step 1 can beeither lossless or lossy in general. Most video compression schemes arelossy because of stringent bit-rate requirements. A successful lossycompression algorithm eliminates redundant and irrelevant information,allowing relatively large errors where they are not likely to bevisually significant and carefully representing aspects of a sequence towhich the human observer is very sensitive.

An image, also referred to as a picture, can be either field-structuredor frame-structured. A frame-structured picture contains information toreconstruct an entire frame, i.e., the combination of one fieldcontaining the odd lines and the other field containing the even lines.A field-structured picture contains information to reconstruct onefield. If the width of each luminance frame (in picture elements orpixels) is denoted as C and the height as R (C is for columns, R is forrows), a frame-structured picture contains information for C×R pixelsand a field-structured picture contains information for C×R/2 pixels.

A macroblock in a field-structured picture contains a 16×8 pixel segmentfrom a single field. A macroblock in a frame-structured picture containsa 16×16 pixel segment from the frame that both fields compose; eachmacroblock contains a 16×8 region from each of the two fields.

Within a group of pictures, three types of pictures can appear. Thedistinguishing difference among the picture types is the compressionmethod used. The first type, Intra mode pictures or I-pictures, arecompressed independently of any other picture. Although there are norequirements for how frequently an I-picture must be interspersed amongthe other types of pictures, it is expected that they will beinterspersed frequently throughout a sequence to facilitate randomaccess and other special modes of operation. Predictivelymotion-compensated pictures (P pictures) are reconstructed from thecompressed data in that picture plus two reconstructed fields frompreviously displayed I or P pictures. Bidirectionally motion-compensatedpictures (B pictures) are reconstructed from the compressed data in thatpicture plus two reconstructed fields from previously displayed I or Ppictures that will be displayed in the future. Because reconstructed Ior P pictures can be used to reconstruct other pictures, they are calledanchor pictures. Additionally, P and B pictures are referred to as Intermode pictures because they rely on information from previous and/orfuture pictures.

The type of a picture determines the methods of motion compensation thatcan be used. The encoder chooses from among these methods for eachmacroblock in the picture. A method of motion compensation is describedby the macroblock mode and motion compensation mode used. There are fourmacroblock modes, intra (I) mode, forward (F) mode, backward (B) mode,and interpolative forward-backward (FB) mode. For I mode, no motioncompensation is used. For the other macroblock modes, 16×16 (S) or 16×8(E) motion compensation modes can be used. For F macroblock mode,dual-prime (D) motion compensation mode can also be used. Thecombination of macroblock mode and motion compensation mode used by amacroblock is referred to as the motion compensation method, includingthe following such methods: F/S, B/S, FB/S, F/E, B/E, FB/E, and F/D.These methods generate predictive macroblocks based on the picture inone or more previous frames or future frames along with information onwhich fields in the previous or future frames use to regenerate theimage at a new location.

The vectors sent for any mode of motion compensation can be inhalf-pixel (half-pel) units. In the case of the F/S, F/E, B/S and B/Emethods of motion compensation, spatial interpolation is used togenerate the predictive macroblock when the vectors used are in half-pelunits. In the case of the FB/S, FB/E, and F/D methods, spatialinterpolation is used to generate the macroblocks that are averaged tomake the predictive macroblock when the vectors used are in half-pelunits.

A common compression technique is transform coding. In several of thecompression standards, the discrete cosine transform (DCT) is thetransform of choice. The compression of an I-picture is achieved by thesteps of 1) taking the DCT of blocks of pixels, 2) quantizing the DCTcoefficients, and 3) entropy coding the result. The DCT operationconverts a block of n×n pixels into an n×n set of transformcoefficients. The DCT transformation by itself is a lossless operation.

The second step, quantization of the DCT coefficients, is the primarysource of lossiness. Denoting the elements of the two-dimensional arrayof DCT coefficients by c_(mn), where m and n can range from 0 to 7,aside from truncation or rounding corrections, quantization is achievedby dividing each DCT coefficient c_(mn) by w_(mn) times Q_(p), withw_(mn) being a weighting factor and Q_(p) being the quantizer parameter.The weighting factor w_(mn) allows coarser quantization to be applied tothe less visually significant coefficients. The quantizer parameterQ_(p) is the primary means of trading off quality vs. bit-rate. Q_(p)can vary from macroblock to macroblock within a picture.

The entropy of an encoder is the average information generated by theencoder, typically expressed in bits per message. The representation ofmessages by binary strings having minimal length in some sense is knownas entropy coding, which is the third step. The video coding standardsoften impose restrictions on the range of motion vectors and define theuse of particular variable length code tables for final entropy codingof the quantized DCT coefficients, motion vectors, and mode informationvectors.

FIG. 1 shows a computer-based encoding system 100 for encoding videoimage signals within which the present invention may be utilized.Analog-to-digital (A/D) converter 102 of encoding system 100 receivesanalog video image signals from a video source. The video source may beany suitable source of analog video image signals such as a video cameraor VCR for generating local analog video image signals or a video cableor antenna for receiving analog video image signals from a remotesource. A/D converter 102 decodes (i.e., separates the signal intoconstituent components) and digitizes each frame of the analog videoimage signals into digital image component signals.

Frame memory 104 receives and stores the digitized component signals assubsampled video images. Image processor 106 accesses captured bitmapsfrom frame memory 104 via bus 108 and generates encoded image signalsthat represent one or more of the captured video images. Depending uponthe particular encoding method implemented, image processor 106 appliesa sequence of compression techniques to reduce the amount of data usedto represent the information in each image. The compression method ofmotion estimation in accordance with the present invention will befurther described below. Pixel data, along with other informationrequired by image processor 106 may be stored in local memory device110. The encoded image is transmitted to host processor 112 via bus 108for storage in host memory 114 and/or in storage 116. Those skilled inthe art will recognize that host processor 112 may in alternativeembodiments perform the functions of image processor 106 describedherein. Similarly, a general memory device such as host memory 114 orstorage 116 may perform the functions of local memory 110 describedherein. Host processor 112 may transmit the encoded image to transmitter118 for transmission to a remote receiver (not shown in FIG. 1), storethe encoded image to storage 116 for future processing, or both. Inaddition, digital-to-analog converter 120 may receive and convertdigital image signals to analog image signals for display in one or morewindows on monitor 122.

Encoding system 100 is preferably a general microprocessor-basedcomputer system with a special purpose video-processing plug-in board.In particular, A/D convertor 102 may be any suitable means for decodingand digitizing analog video image signals. Image processor 106 may beany suitable processor or other means for receiving digitized videoimage component signals as subsampled frames, and for encodingsubsampled video image signals, where the processor or other means iscapable of implementing functions such as a forward discrete cosinetransform and a motion estimation and block matching procedures asdescribed in further detail below. Memory devices 110, 114 may be anysuitable computer memory device such as a dynamic random access memory(DRAM) device, read-only memory device (ROM), or a combination of DRAMand ROM. Storage device 116 may be any suitable means for storingdigital signals such as a computer hard drive. Bus 108 may be anysuitable digital signal transfer device such as an Industry StandardArchitecture (ISA) bus, and Extended ISA (EISA) bus, or a PeripheralComponent Interface (PCI) bus. A/D converter 102, frame memory 104,image processor 106, and local memory 110 may be contained on a singleplug-in board capable of being interfaced with bus 108. Host processor112 may be any suitable means for controlling the operations of theimage processor 106, such as a microprocessor. Transmitter 118 may beany suitable means for transmitting digital signals to a remote receiverand is operable to transmit digital signals over telephone lines, RFantenna, local area network, or remote area network. D/A converter 120may be any suitable device for converting digital image signals toanalog image signals and may be implemented through a display system,such as a VGA or SVGA system. Monitor 122 may be any means fordisplaying analog image signals, such as a VGA monitor.

The encoding system 100 discussed herein is representative of a typicalencoding system, however, it is recognized that the present invention isalso applicable to encoding systems having different components andinterrelation among the components.

FIG. 2 is a block diagram of a simplified view of a video encoder 200currently known in the art including frame memory 201, motion estimationunit 202, rate control unit 203, motion compensation unit 213, transformunit 214, quantization unit 215, variable length encoder unit 219, andoutput buffer 221. The input to the video encoder of FIG. 2 is signal209. The output is compressed bit stream 222. For the encoder of FIG. 2,the input pixel data is stored in frame memory 201. Motion estimationunit 202 performs motion estimation for each macroblock. In particular,for each macroblock motion estimation unit 202 decides which macroblockmode and which motion compensation mode will be used, which motionvector(s) will be used, and an estimate of how precise the effectivemotion compensation is (that is, how well the predictive macroblockmatches the macroblock to be encoded.) This estimate and the mode andvector decisions are then sent to rate control unit 203 as signal 227.It is the function of rate control unit 203 to determine the value ofQ_(p) to be used in each macroblock. This determination is made :basedon the information from the motion estimation unit (signal 227) and thefullness of the output buffer (signal 223).

Motion estimation unit 202 sends the macroblock mode, motioncompensation mode and motion vector(s) as signal 212 to motioncompensation unit 213. This signal, together with pixel data retrievedfrom frame memory 201 as signal 211 is used by compensation unit 213 tocompute a difference macroblock, which is sent as signal 226 totransform unit 214. The transform unit 214 segments the differencemacroblock (signal 226) into blocks and computes the DCT of each block.These are sent as signal 225 to the quantization unit 215. Thequantization unit 215 quantizes each DCT coefficient based on thequantization parameter Q_(p), sent as signal 217 from rate control unit203. The quantized DCT coefficients are sent as the signal 224 tovariable length encoder unit 219.

For each macroblock, variable length encoder unit 219 produces acompressed representation of the quantized DCT coefficients (signal 224from quantization unit 215), the macroblock mode, motion compensationmode and motion vectors (signal 216 from motion estimation unit 202),and Q_(p) (signal 218 from rate control unit 203). The compressedmacroblock is sent as signal 220 to output buffer 221. Output buffer 221receives the compressed representation of each macroblock from variablelength encoder unit 219 as signal 220. It then sends out the bits thatit has received on a first come, first serve basis as signal 222. Asignal indicating the fullness of the output buffer is sent as signal223 to rate control unit 203. Rate control unit 203 will in generalrespectively increase or decrease the value of Q_(p) for futuremacroblocks if the output buffer 221 is respectively nearly full ornearly empty).

Block-based motion estimation 202 traditionally considers only the sumof the absolute differences (SAD) between the current and the referenceblocks to find the motion vectors, while ignoring the effects of thequantization 215 and the fixed variable length coding tables in variablelength encoder unit 219. Mathematically, the problem may be formulatedas

q _(k,i) =X _(k) −{circumflex over (X)} _(k|i,j)

follows. Let X_(k) be the current macroblock to be coded. Let{circumflex over (X)}_(k|i,j) with j being the index of the referenceframe, be the prediction made by the motion estimation algorithm byusing a motion vector, mv_(i) in the search window W. The displacedframe difference representing the prediction error is given by

Let D be the distortion measure used (sum of absolute differences orsquared error). A distortion given by D(q_(k,i))=D(X_(k)−{circumflexover (X)}_(k|i,j)) is introduced because of choosing the motion vectormv_(i). Motion estimation 202 chooses the motion vector in the searchwindow W which minimizes this distortion. That is

D _(k)=min{D(X _(k) −{circumflex over (X)} _(k|i,j))}mv _(i) εW

The displaced frame differences (DFD's) associated with this choice ofthe motion vector mv_(min) generated in motion compensation 213 by

q _(k) =X _(k) −{circumflex over (X)} _(k|minj).

The DFD's are then transformed using 8×8 discrete cosine transform (DCT)(Q_(k)) in transform 214 and quantized ({circumflex over (Q)}_(d)) usingthe quantization parameter Q_(p) in quantization 215.

Since the variable length code tables in variable length encoder unit219 for motion vectors are predefined by the standards based on severaltypes of image sequences, the motion vector selected using the least sumof absolute differences criterion may not be the optimal choice. This isparticularly important in low bit-rate video coding, where modeinformation vectors contain a proportionately higher amount ofinformation. Hence, some known methods include the bits required formode information vectors in the minimization criteria. The optimizationis performed using known Lagrange multiplier techniques.

The present invention further extends the Lagrange multiplier techniqueto improve motion estimation and the video encoding process. When thequantizer value for the current macroblock is known, the number of bitsneeded to code the quantized DCT coefficients can be included. Further,when such computations are performed, it is also possible to obtain thetrue distortion representing the quantization effects rather than thesum of absolute differences or mean squared error between the uncodedand the predicted macroblocks to be included in the objective function.

In the present invention, the block matching procedures between thecurrent macroblock and the search area are used to find the appropriatemotion vectors. The search area is defined by the range of the motionvectors permitted by the coding standard. In prior methods, the sum ofabsolute differences is used as a distortion measure and the motionvectors are chosen to minimize the prediction error, i.e., thedifferences between the current macroblock and the reference macroblock.However, the present video encoder also minimizes the overall distortionbetween the original and the reconstructed macroblock for the: availablebit-rate, thereby minimizing the overall encoding distortion and notjust the prediction error.

Let B_(k) be the total number of bits it would take to code ({circumflexover (Q)}_(k)) using the variable length code tables defined by thevideo coding algorithm along with the mode information vector of S_(k)bits (for coding the differential motion vectors, mode information,etc.). A decoder receives B_(k) bits from the bit stream andreconstructs the quantized transform coefficients along with the motionvectors. The motion vectors are then used to get the macroblockprediction {circumflex over (X)}_(k|minj) from the reference frame j.The quantized transform coefficients are inverse quantized using Q_(p)which is also sent as a part of the mode information vector S_(k) andthen inverse transformed using an 8×8 inverse DCT to obtain {circumflexover (q)}_(k). The macroblock is finally reconstructed by adding thequantized DFD to the prediction. That is:

{circumflex over (X)}_(k) ={circumflex over (X)} _(k|minj) +{circumflexover (q)} _(k).

The distortion between the original macroblock X_(k) and thereconstructed macroblock {circumflex over (X)}_(k) is given by

D(X _(k) −{circumflex over (X)} _(k))=D(q _(k) −{circumflex over (q)}_(k)).

From the above equation, the final reconstruction error is a function ofboth the prediction and the quantization process. In the presentinvention, the motion vectors are chosen to minimize the overall codingdistortion and not just the average prediction error.

Given the quantization scheme and the bit stream syntax, the only searchparameters which can be used to minimize the overall distortion betweenthe current and the reconstructed macroblock are the motion vectors andmode information vectors. Mode vectors include information pertaining toeach macroblock including quantization parameter Q_(p), macroblockaddress, macroblock type (intra/inter), motion type(frame/field/overlapped motion), DCT type (frame/field), coded blockpattern to indicate which blocks in a macroblock have non-zero DCTcoefficients, and quantization scale factor. In addition, most videocoding systems have a constraint on the average bit-rate. In practice,for the given maximum frame rate, this constraint on the bit-rate can besuitably changed to a target number of bits for the current picture. Anappropriate rate control scheme can transform it to the averagebits/macroblock. Let B be the average target bit-rate/macroblock. Onegoal of the present video coding algorithm is to find the motion vectorand corresponding mode vector to minimize the distortion between theoriginal and the reconstructed macroblock with the constraint that thenumber of bits to encode a macroblock is less than or equal to theaverage bit rate. That is:

min{D(X _(k) −{circumflex over (X)} _(k))}subject to B _(k) ≦B.mv _(i)εW,mojεM

Where moj denotes a candidate mode vector and M denotes the mode vectorsearch window. Most rate allocation algorithms tend to vary Q_(p) onlyonce per row of macroblocks or even once a picture. Assuming that Q_(p)is a constant for the whole frame, the unconstrained motion estimationproblem can then be stated as:

min{D(X _(k) −{circumflex over (X)} _(k))}mv _(i) εW,mojεM

Note that Q_(p) need not be constant over a frame.

The above unconstrained motion estimation problem can then be convertedto a constrained motion estimation problem by using known Lagrangemultiplier techniques. The problem can then be stated as:

min{D(X _(k) −{circumflex over (X)} _(k))+λ*(B_(k,i) −B)}mv _(i)εW,mojεM

where λ is a constant for a given bit-rate. Since B is a constant, theproblem of the rate-constrained motion estimation algorithm, given Q_(p)and λ, is to find the motion vector in the search window W whichminimizes the modified distortion

D'((X _(k) −{circumflex over (X)} _(k))=D(X _(k) −{circumflex over (X)}_(k))+λ*B _(k,i)  (Equation 1)

FIG. 3 shows a block diagram of an embodiment of the present inventionfor a video encoder preprocessor 300 including frame memory 302,candidate motion vector and mode information vector unit 304, ratecontrol unit 306, motion compensation unit 308, transform unit 310,quantization unit 312, inverse quantization unit 314, inverse transformunit 316, distortion calculator unit 318, intramode switch 320, modeinformation estimator unit 322, quantization coefficient estimator unit324, multiplier unit 326, minimum distortion unit 328, and buffer 330.The input to video encoder preprocessor 300 of FIG. 3 is pixel datasignal 332. The output is compressed bit stream signal 334 which isstored in output buffer 330 pending transmission to a decoder. Inputpixel data signals 332 are stored in frame memory 302. For eachmacroblock, candidate motion vectors and corresponding mode informationvectors are generated for encoder preprocessing, which evaluates thecost for each candidate in terms of distortion rate and bit rate, andselects the candidate with the minimum cost. The selected candidate isthen output to buffer 330 pending transmission to a video encoder (notshown) for encoding.

Depending on whether the mode is Intra or Inter mode, the macroblock isprocessed differently as follows. For Intra mode, current macroblocksignal 336 is sent directly to transform unit 310. For Inter mode,motion compensation unit 308 computes a prediction signal 338 for thecurrent block using reference blocks from frame memory 302. A displacedframe difference (DFD) signal based on the difference between predictionsignal 338 and current macroblock signal 336 is sent as block signal 350to transform unit 310. Transform unit 310 segments block signal 350 intoblocks and computes the DCT of each block. The DCT's of each block areoutput as transform signal 340.

Rate control unit 306 determines the value of Q_(p) to be used in eachmacroblock. In the present invention, this determination may be selectedbefore the motion estimation for the macroblock begins using knowntechniques when Q_(p) is selected based on the fulness of output buffer328. Such techniques are discussed in “Motion Compensated Video Codingwith Adaptive Perceptual Quantization,” by A. Puri and R. Aravind, IEEETransactions on Circuits and Systems on Video Technology, vol. CSVT-1,no. 4, pp. 351-361, December 1991.

Transform signal 340 and mode information vector signal 342 are sent toquantization unit 312 for quantization. Additionally, mode informationand quantization parameter Q_(p) are input to quantization unit 312 and-inverse quantization unit 314. Quantization unit 312 quantizes each DCTcoefficient based on the quantization parameter Q_(p) and generatesquantization signal 344, which is then input to mode informationestimator unit 322, quantization coefficient estimator unit 324, andinverse quantization unit 314.

Mode information estimator unit 322 estimates the bits required toencode the motion vectors and other mode information, and determineswhether any of the blocks in a macroblock need to be coded. Modeinformation estimator unit 322 determines how this information is to besent in bit stream signal 334 based on the motion vector predictionscheme employed in the relevant video coding standard. It is importantto note that only an estimate of the number of bits required to encodeall the mode information is needed and not the actual number of bits.

Quantization coefficient estimator unit 324 estimates the number of bitsrequired to encode the quantized transform coefficients based onquantization signal 344. Any suitable scheme may be utilized to predictthe number of bits required to encode the quantized coefficients basedon the variable length code tables in the relevant coding standard.Actually counting the number of bits required to represent the quantizedblocks provides the most accurate value of the number of bits requiredto encode the quantized coefficients.

The quantized coefficients (quantization signal 344) and modeinformation vector signal 342 are input to inverse quantization unit314. Inverse quantization signal 346 is input to inverse transform unit316. Inverse transform signal 348 and block signal 350 are input todistortion calculator unit 318 wherein the distortion between blocksignal 350 and inverse transform signal 348, which represents thereconstructed data, is determined. Any distortion measure whichindicates the difference between the signals, such as mean squarederror, can be utilized.

Signals 352 output from mode information estimator unit 322 and signal354 output from quantization coefficient estimator unit 324 are summedand input as bit length signal 356 to multiplier unit 326. A multiplier,such as Lagrange multiplier, λ, is applied to bit length signal 356 togenerate bit-rate signal 358 proportional to the bit-rate for themacroblock given the candidate motion vector and mode informationvector.

Bit-rate signal 358 and distortion signal 360 are summed to form motionestimation signal 362 according to Equation 1 hereinabove. Eachcandidate motion vector and mode information vector is preprocessed invideo encoder preprocessor 300. Minimum distortion unit 328 determinesthe combination of motion vector and mode information vector whichminimizes the motion estimation signal 362. The minimizing combinationis sent as bit stream signal 334 to buffer 330. The data in buffer 330is output to an encoder unit (not shown) for encoding.

FIG. 4 shows another embodiment of a video encoder preprocessor 400which is similar to video encoder preprocessor 300 with the exceptionthat distortions introduced by the quantization unit 312 are calculatedin transform unit 310, thereby eliminating the need for inversetransform unit 316. Note also that mode information estimator unit 322and quantization coefficient estimator unit 324 may be combined in oneestimate unit.

The present invention can also be used for rate control using thequantization parameter Q_(p). This is achieved by performing theminimization of the objective function over all candidate quantizationparameter (Q_(p)) values with the additional constraint of the allowablenumber of bits.

min{D(X _(k) −{circumflex over (X)} _(k))}mv _(i) εW,Q _(p)

subject to B_(k)≦B. This is especially useful when Q_(p) varies morethan once per row of macroblocks or even more than once per frame.

Advantageously, the present invention provides a video encoderpreprocessor that takes into account both distortion and the amount ofdata required for a candidate motion vector and mode information vectorin determining the optimal combination to be processed by the actualvideo encoder. Traditional schemes were limited to considering themotion estimation and the quantization process separately, leading tosub-optimal results in many situations. For example, choosing the motionvector which minimizes the sum of the absolute differences and the meansquared error is not the optimal choice with regard to rate-distortion,since the number of bits required to encode a DFD is ignored. Further,bits for mode parameters such as motion vectors, coded block pattern,and macroblock type, become a sizable amount of encoded data at lowbit-rates, and therefore cannot be ignored for optimal encoding.Additionally, the present invention takes into account whether amacroblock is coded as an Inter or Intra mode. This further optimizesencoding since the determination of whether to use Inter or Intra modefor a macroblock is also based on rate distortion.

Video encoder preprocessor 300 may be implemented in hardware, software,firmware, or a combination of hardware, software and firmware. A knowndata processor, such as a microprocessor-based computer, as well asother hardware, firmware, and software devices, may be used to implementthe present invention. The present invention may be implemented so thatvarious preprocessing units execute in parallel. Additionally, localmemory 110 may provide rapid access to the data by placing the searcharea and the current macroblock pixels in cache memory for quick,repeated access by the processing units in video encoder preprocessor300. Computer processors with one or more accelerators for motioncompensation unit 308 or other processing units in video encoderpreprocessor 300 may also be used.

While the invention has been described with respect to the embodimentsand variations set forth above, these embodiments and variations areillustrative and the invention is not to be considered limited in scopeto these embodiments and variations. Accordingly, various otherembodiments and modifications and improvements not described herein maybe within the spirit and scope of the present invention, as defined bythe following claims.

What is claimed is:
 1. A method for optimizing the video encodingprocess for a macroblock in a block-based video encoder wherein aplurality of candidate motion vectors, mode information related to eachof the motion vectors, and quantized discrete cosine transformcoefficients based on the macroblock and the candidate motion vectorsare provided, the method comprising: (a) estimating the length of a bitstream that would be required to encode the quantized discrete cosinetransform coefficients, the motion vectors, and the mode information;(b) generating a bit-rate term based on the estimated length of the bitstream; (c) determining a measure of distortion based on the quantizeddiscrete cosine transform coefficients; (d) determining a motionestimation signal based on the measure of distortion and the bit-rateterm; (e) repeating (a) through (d) for each candidate motion vector;and (f) selecting the motion vector having the minimum motion estimationsignal.
 2. The method, as recited in claim 1, further comprising: (g)outputting the length of the bit stream and information associated withthe selected motion vector to an output buffer.
 3. The method, asrecited in claim 1, wherein (b) further comprises using a Lagrangemultiplier to determine the bit-rate term.
 4. The method, as recited inclaim 1, wherein (a) further comprises encoding the quantized discretecosine transform coefficients, the motion vectors, and the modeinformation in a compressed format.
 5. The method, as recited in claim1, wherein (d) further comprises determining a motion estimation signalbased on the measure of distortion, the bit-rate term, and thequantization parameter.
 6. A method for optimally encoding motioncompensated video, the method comprising: (a) generating at least onecandidate motion vector; (b) generating mode information related to eachcandidate motion vector; (c) determining a quantization parameter; (d)determining a displaced frame difference macroblock based on themacroblock and the at least one candidate motion vector; (e) segmentingthe displaced frame difference macroblock into blocks and determining adiscrete cosine transform coefficient for each block; (f) quantizingeach discrete cosine transform coefficient based on the quantizationparameter; (g) encoding the quantized discrete cosine transformcoefficients, the candidate motion vector, and the mode information intoa bit stream; (h) determining the length of the bit stream; (i)generating a bit-rate term based on the length of the bit stream; (j)determining a reconstructed macroblock based on inverse quantization andinverse transformation of the discrete cosine transform coefficients;(k) determining a measure of distortion based on the current macroblockand the reconstructed macroblock; (l) determining a motion estimationsignal based on the measure of distortion and the bit-rate term; (m)repeating (a) through (l) for each candidate motion vector; and (n)selecting the candidate motion vector having the minimum motionestimation signal.
 7. The method, as recited in claim 6, wherein (c)further comprises determining the quantization parameter based on thelength of the bit stream.
 8. The method, as recited in claim 6, wherein(c) further comprises determining the quantization parameter based onthe at least one candidate motion vector and the mode informationrelated to the at least one candidate motion vector.
 9. The method, asrecited in claim 6, wherein the quantization parameter is determinedbefore determining the at least one candidate motion vector and the modeinformation related to the motion vector.
 10. The method, as recited inclaim 6, wherein (h) further comprises using a Lagrange multiplier todetermine the bit-rate term.
 11. The method, as recited in claim 6,wherein (g) further comprises encoding the quantized discrete cosinetransform coefficients, the at least one candidate motion vector, andthe mode information in a compressed format.
 12. The method, as recitedin claim 6, wherein (k) further comprises determining the motionestimation signal based on the measure of distortion, the bit-rate term,and the quantization parameter.
 13. The method, as recited in claim 6,wherein (g) through (h) are executed in parallel with (i) through (j).14. An apparatus for optimizing encoding of a macroblock, wherein aplurality of candidate motion vectors, mode information related to eachof the motion vectors, and quantized discrete cosine transformcoefficients based on the macroblock and the candidate motion vectors isprovided, the apparatus comprising: a video encoder preprocessorconnected to receive the quantized discrete cosine transformcoefficients, the candidate motion vectors, and the mode information,the video encoder preprocessor being operable to estimate the length ofa bit stream that would be required to encode each candidate motionvector, mode information corresponding to each candidate motion vector,and quantized discrete cosine transform coefficients corresponding toeach candidate motion vector, and to transmit the estimated length ofthe bit stream; a Lagrange multiplier unit connected to receive theestimated length of the bit stream, the Lagrange multiplier unit beingoperable to generate a bit-rate term based on the estimated length ofthe bit stream, and to transmit the bit-rate term; an inversequantization unit connected to receive the discrete cosine transformcoefficients, the inverse quantization unit being operable to determineinverse quantized discrete cosine transform coefficients and to transmitthe inverse quantized discrete cosine transform coefficients; adistortion calculator unit connected to receive the inverse quantizeddiscrete cosine transform coefficients, the distortion calculator unitbeing operable to generate a distortion signal; and a minimum distortionunit operable to determine a motion estimation signal based on thedistortion signal and the bit-rate term for each candidate motionvector, and to select the motion vector having the minimum motionestimation signal.
 15. The apparatus, as recited in claim 14, whereinthe multiplier unit is further operable to use a Lagrange multiplier todetermine the bit-rate term.
 16. The apparatus, as recited in claim 14,wherein the apparatus is operable to determine the motion estimationsignal based on the measure of distortion, the bit-rate term, and thequantization parameter.
 17. An apparatus for optimizing a block-basedvideo encoder, the apparatus comprising: frame memory connected toreceive pixel data for each macroblock; a candidate motion vector andmode information vector unit being operable to generate at least onecandidate motion vector, and mode information related to the motionvector, the candidate motion vector and mode information vector unitbeing further operable to transmit the motion vector and the modeinformation; a rate control unit operable to determine a quantizationparameter, and connected to transmit the quantization parameter to thecandidate motion vector and mode information vector unit; a motioncompensation unit connected to receive pixel data for each macroblock,and the motion vector from the motion estimator unit, the motioncompensation unit being operable to determine a displaced framedifference macroblock based on the pixel data and the motion vector, andto transmit the displaced frame difference macroblock; a transform unitconnected to receive the displaced frame difference macroblock, thetransform unit being operable to segment the displaced frame differencemacroblock into blocks, to determine a discrete cosine transformcoefficient for each block, and to transmit the discrete cosinetransform coefficients; a quantization unit connected to receive thediscrete cosine transform coefficients, the quantization unit beingoperable to quantize each discrete cosine transform coefficient based onthe quantization parameter, and to transmit the quantized discretecosine transform coefficients; an inverse quantization unit connected toreceive the quantized discrete cosine transform coefficients, theinverse quantization unit being operable to determine inverse quantizeddiscrete cosine transform coefficients and to transmit the inversequantized discrete cosine transform coefficients; a distortioncalculator unit operable to determine a distortion signal based on themacroblock and the inverse quantized discrete cosine transformcoefficients; an estimate unit operable to estimate the length of a bitstream that would be required to encode mode information correspondingto each candidate motion vector, and quantized discrete cosine transformcoefficients corresponding to each candidate motion vector, and totransmit the length of the bit stream; a multiplier unit connected toreceive the length of the bit stream, the multiplier unit being operableto generate a bit-rate term based on the length of the bit stream, andto transmit the bit-rate term; and a minimum distortion unit operable todetermine a motion estimation signal based on the distortion signal andthe bit-rate term for each candidate motion vector, and to select themotion vector corresponding to the minimum motion estimation signal. 18.The apparatus, as recited in claim 17, wherein the Lagrange multiplierunit is further operable to use a Lagrange multiplier to determine thebit-rate term.
 19. The apparatus, as recited in claim 17, furthercomprising: an inverse transform unit connected to receive the inversequantized discrete cosine transform coefficients, the inverse transformunit being operable to generate a reconstructed macroblock based on theinverse transformation of the inverse quantized discrete cosinetransform coefficients, wherein the distortion calculator unitdetermines the distortion signal based on the reconstructed macroblockand the macroblock.
 20. The apparatus, as recited in claim 17, whereinthe video encoder preprocessor unit is further operable to encode thequantized discrete cosine transform coefficients, the motion vectors,and the mode information in a compressed format.
 21. The apparatus, asrecited in claim 17, wherein the apparatus is further operable totransmit the bit stream and the selected motion vector to an outputbuffer.
 22. The apparatus, as recited in claim 17, wherein the ratecontrol unit determines the quantization parameter based on the amountof data in the output buffer.
 23. The apparatus, as recited in claim 17,wherein the rate control unit determines the quantization parameterbased on the at least one candidate motion vector and the modeinformation related to the at least one motion vector.
 24. Theapparatus, as recited in claim 17, wherein the rate control unitdetermines the quantization parameter before the motion estimation unitdetermines the at least one candidate motion vector and the modeinformation related to the at least one motion vector.
 25. Theapparatus, as recited in claim 17, wherein the multiplier unit isfurther operable to use a Lagrange multiplier to determine the bit-rateterm.
 26. The apparatus, as recited in claim 17, wherein the videoencoder preprocessor unit is further operable to encode the quantizeddiscrete cosine transform coefficients, the motion vectors, and the modeinformation in a compressed format.
 27. The apparatus, as recited inclaim 17, wherein the motion estimation signal is based on the measureof distortion, the bit-rate term, and the quantization parameter.